1 package jrre.gui;
2
3 import jrre.JRRE;
4
5 import java.awt.*;
6 import javax.swing.*;
7 import javax.swing.tree.*;
8 import java.awt.event.*;
9
10 public class OperandFrameGui extends JFrame {
11
12 private static JTree methodAreaTree = new JTree();
13 private static DefaultMutableTreeNode treeRoot;
14 private static DefaultMutableTreeNode frameRoot;
15 private static DefaultMutableTreeNode lastAdded;
16 private static DefaultMutableTreeNode lastFrame;
17 private static DefaultTreeModel treeModel;
18 private static int classCount = 0;
19
20 private static java.util.Vector frameVector = new java.util.Vector();
21
22 public OperandFrameGui(){
23
24 super("Operand Frames");
25
26 classCount = 0;
27
28 // Set up and add tree.
29 treeRoot = new DefaultMutableTreeNode("Operand Frames");
30 frameRoot = treeRoot;
31
32 treeModel = new DefaultTreeModel(treeRoot);
33
34 methodAreaTree = new JTree(treeModel);
35
36 JPanel treePanel = new JPanel();
37 treePanel.add(methodAreaTree);
38
39 JScrollPane scrollPane = new JScrollPane(methodAreaTree);
40 //scrollPane.add(methodAreaTree);
41 Container content = getContentPane();
42 content.add(scrollPane);
43
44 addWindowListener(new WindowDestroyer());
45
46 setSize(300,300);
47 setLocation(100, 0);
48
49 if(JRRE.guiOn())
50 setVisible(true);
51 }
52
53 public void clear(){
54 classCount = 0;
55
56 // Set up and add tree.
57 treeRoot.removeAllChildren();
58 frameRoot = treeRoot;
59 }
60
61 public static void pushFrame(String frameName){
62
63 //lastFrame = frameRoot;
64 frameVector.add(frameRoot);
65 frameRoot = new DefaultMutableTreeNode(frameName);
66
67 treeRoot.add(frameRoot);
68 treeModel.reload();
69
70 //TreePath path = new TreePath(frameRoot.getPath());
71 //methodAreaTree.expandPath(path);
72 }
73
74 public static void popFrame(){
75 try{
76 treeRoot.remove(frameRoot);
77 }
78 catch(Exception e){System.out.println(e);}
79 //frameRoot = lastFrame;
80 frameRoot = (DefaultMutableTreeNode)frameVector.remove(frameVector.size()-1);
81 treeModel.reload();
82 }
83
84 public void push(String className){
85
86 DefaultMutableTreeNode classToAdd = new DefaultMutableTreeNode(className);
87 lastAdded = classToAdd;
88
89 //frameRoot.add(classToAdd);
90 treeModel.insertNodeInto(classToAdd, frameRoot,
91 frameRoot.getChildCount());
92 treeModel.reload();
93
94 TreePath path = new TreePath(treeModel.getPathToRoot(classToAdd));
95 //TreePath path = new TreePath(classToAdd.getPath());
96 methodAreaTree.expandPath(path);
97
98 methodAreaTree.scrollPathToVisible(new TreePath(classToAdd.getPath()));
99
100 }
101
102 public void pop(){
103
104 int childCount = frameRoot.getChildCount();
105
106 if(childCount == 0)
107 return;
108
109 try{
110 frameRoot.remove(frameRoot.getChildCount()-1);
111 }
112 catch(Exception e){System.out.println("OpFrameGui: "+e);}
113 treeModel.reload();
114
115 }
116
117 class WindowDestroyer extends WindowAdapter{
118 public void windowClosing(WindowEvent e){
119 System.exit(0);
120 }
121 }
122
123 }
124
This page was automatically generated by Maven